home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / WindowsFileChooserUI.java < prev    next >
Text File  |  1998-06-30  |  19KB  |  622 lines

  1. /*
  2.  * @(#)WindowsFileChooserUI.java    1.7 98/04/14
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.windows;
  22.  
  23. import com.sun.java.swing.*;
  24. import com.sun.java.swing.preview.*;
  25. import com.sun.java.swing.preview.filechooser.*;
  26. import com.sun.java.swing.event.*;
  27. import com.sun.java.swing.plaf.*;
  28. import com.sun.java.swing.plaf.basic.*;
  29. import java.awt.*;
  30. import java.awt.event.*;
  31. import java.beans.*;
  32. import java.io.File;
  33. import java.io.IOException;
  34. import java.util.*;
  35.  
  36. /**
  37.  * Basic L&F implementation of a FileChooser.  
  38.  *
  39.  * @version 1.7 04/14/98
  40.  * @author Jeff Dinkins
  41.  */
  42. public class WindowsFileChooserUI extends BasicFileChooserUI {
  43.     // These are all private because we don't want to lock the internal
  44.     // implementation down. If you really need to subtype WindowsFileChooser,
  45.     // copy the source and modify the copy.
  46.     private JPanel centerPanel;
  47.  
  48.     private JComboBox directoryComboBox;    
  49.     private DirectoryComboBoxModel directoryComboBoxModel;    
  50.     private Action directoryComboBoxAction = new DirectoryComboBoxAction();
  51.  
  52.     private FilterComboBoxModel filterComboBoxModel;
  53.  
  54.     private JTextField filenameTextField;
  55.  
  56.     private JList list;
  57.  
  58.     private JButton approveButton;
  59.     private JButton cancelButton;
  60.  
  61.     private JComboBox filterComboBox;
  62.  
  63.     private JPanel bodyPanel = null;
  64.  
  65.     private static final Dimension hstrut10 = new Dimension(10, 1);
  66.     private static final Dimension hstrut25 = new Dimension(25, 1);
  67.     private static final Dimension vstrut10 = new Dimension(1, 10);
  68.     private static final Insets shrinkwrap = new Insets(0,0,0,0);
  69.  
  70.     private static int PREF_WIDTH = 500;
  71.     private static int PREF_HEIGHT = 300;
  72.     private static Dimension PREF_SIZE = new Dimension(PREF_WIDTH, PREF_HEIGHT);
  73.  
  74.     private static int MIN_WIDTH = 400;
  75.     private static int MIN_HEIGHT = 200;
  76.     private static Dimension MIN_SIZE = new Dimension(MIN_WIDTH, MIN_HEIGHT);
  77.  
  78.     private static int LIST_MIN_WIDTH = 400;
  79.     private static int LIST_MIN_HEIGHT = 100;
  80.     private static Dimension LIST_MIN_SIZE = new Dimension(LIST_MIN_WIDTH, LIST_MIN_HEIGHT);
  81.  
  82.     //
  83.     // ComponentUI Interface Implementation methods
  84.     //
  85.     public static ComponentUI createUI(JComponent c) {
  86.         return new WindowsFileChooserUI((JFileChooser)c);
  87.     }
  88.  
  89.     public WindowsFileChooserUI(JFileChooser filechooser) {
  90.     super(filechooser);
  91.     }
  92.             
  93.     public void installUI(JComponent c) {
  94.     super.installUI(c);
  95.     }
  96.  
  97.     public void installComponents() {
  98.     // set to a Y BoxLayout. The chooser will be layed out top to bottom.
  99.     getFileChooser().setLayout(new BoxLayout(getFileChooser(), BoxLayout.Y_AXIS));
  100.     getFileChooser().add(Box.createRigidArea(vstrut10));
  101.     
  102.     // ********************************* //
  103.     // **** Construct the top panel **** //
  104.     // ********************************* //
  105.  
  106.     // Directory manipulation buttons
  107.     JPanel topPanel = new JPanel();
  108.     topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
  109.  
  110.     // Add the top panel to the fileChooser
  111.     getFileChooser().add(topPanel);
  112.     getFileChooser().add(Box.createRigidArea(vstrut10));
  113.     
  114.     // ComboBox Label
  115.     JLabel l = new JLabel("Look in:");
  116.     l.setAlignmentX(JComponent.LEFT_ALIGNMENT);
  117.     l.setAlignmentY(JComponent.CENTER_ALIGNMENT);
  118.     topPanel.add(Box.createRigidArea(hstrut10));
  119.     topPanel.add(l);
  120.     topPanel.add(Box.createRigidArea(hstrut25));
  121.     
  122.     // CurrentDir ComboBox
  123.     directoryComboBox = new JComboBox();
  124.     directoryComboBoxModel = createDirectoryComboBoxModel();
  125.     directoryComboBox.setModel(directoryComboBoxModel);
  126.     directoryComboBox.addActionListener(directoryComboBoxAction);
  127.     directoryComboBox.setRenderer(createDirectoryComboBoxRenderer());
  128.     directoryComboBox.setAlignmentX(JComponent.LEFT_ALIGNMENT);
  129.     directoryComboBox.setAlignmentY(JComponent.CENTER_ALIGNMENT);
  130.  
  131.     topPanel.add(directoryComboBox);
  132.     topPanel.add(Box.createRigidArea(hstrut10));
  133.     
  134.     // Up Button
  135.     JButton b = new JButton(upFolderIcon);
  136.     b.setToolTipText("Up One Level");
  137.     b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
  138.     b.setAlignmentY(JComponent.CENTER_ALIGNMENT);
  139.     b.setMargin(shrinkwrap);
  140.     b.setFocusPainted(false);
  141.     b.addActionListener(getChangeToParentDirectoryAction());
  142.     topPanel.add(b);
  143.     topPanel.add(Box.createRigidArea(hstrut10));
  144.     
  145.     // Home Button
  146.     b = new JButton(homeFolderIcon);
  147.     b.setToolTipText("Home");
  148.     b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
  149.     b.setAlignmentY(JComponent.CENTER_ALIGNMENT);
  150.     b.setMargin(shrinkwrap);
  151.     b.setFocusPainted(false);
  152.     b.addActionListener(getGoHomeAction());
  153.     topPanel.add(b);
  154.     topPanel.add(Box.createRigidArea(hstrut10));
  155.     
  156.     // New Directory Button
  157.     b = new JButton(newFolderIcon);
  158.     b.setToolTipText("Create New Folder");
  159.     b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
  160.     b.setAlignmentY(JComponent.CENTER_ALIGNMENT);
  161.     b.setMargin(shrinkwrap);
  162.     b.setFocusPainted(false);
  163.     b.addActionListener(getNewFolderAction());
  164.     topPanel.add(b);
  165.     topPanel.add(Box.createRigidArea(hstrut10));
  166.     
  167.     // List Button
  168.     JToggleButton tb = new JToggleButton(listViewIcon);
  169.     tb.setToolTipText("List");
  170.     tb.setEnabled(false);
  171.     tb.setFocusPainted(false);
  172.     tb.setAlignmentX(JComponent.LEFT_ALIGNMENT);
  173.     tb.setAlignmentY(JComponent.CENTER_ALIGNMENT);
  174.     tb.setMargin(shrinkwrap);
  175.     topPanel.add(tb);
  176.     
  177.     // Details Button
  178.     tb = new JToggleButton(detailsViewIcon);
  179.     tb.setToolTipText("Details");
  180.     tb.setFocusPainted(false);
  181.     tb.setSelected(true);
  182.     tb.setEnabled(false);
  183.     tb.setAlignmentX(JComponent.LEFT_ALIGNMENT);
  184.     tb.setAlignmentY(JComponent.CENTER_ALIGNMENT);
  185.     tb.setMargin(shrinkwrap);
  186.     topPanel.add(tb);
  187.     topPanel.add(Box.createRigidArea(hstrut10));
  188.  
  189.     // ************************************** //
  190.     // ******* Add the directory pane ******* //
  191.     // ************************************** //
  192.     centerPanel = new JPanel(new BorderLayout());
  193.     JPanel p = createList();
  194.     p.setMinimumSize(LIST_MIN_SIZE);
  195.     centerPanel.add(p, BorderLayout.CENTER);
  196.     centerPanel.add(getAccessoryPanel(), BorderLayout.EAST);
  197.     JComponent accessory = getFileChooser().getAccessory();
  198.     if(accessory != null) {
  199.         getAccessoryPanel().add(accessory);
  200.     }
  201.     getFileChooser().add(centerPanel);
  202.  
  203.     // ********************************** //
  204.     // **** Construct the bottom panel ** //
  205.     // ********************************** //
  206.     JPanel bottomPanel = new JPanel();
  207.     bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));
  208.     bottomPanel.add(Box.createRigidArea(hstrut10));
  209.  
  210.     // Add the bottom panel to file chooser
  211.     getFileChooser().add(Box.createRigidArea(vstrut10));
  212.     getFileChooser().add(bottomPanel);
  213.     getFileChooser().add(Box.createRigidArea(vstrut10));
  214.     
  215.     // labels
  216.     JPanel labelPanel = new JPanel();
  217.     labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS));
  218.  
  219.     l = new JLabel("File name:");
  220.     labelPanel.add(l);
  221.  
  222.     labelPanel.add(Box.createRigidArea(vstrut10));
  223.  
  224.     l = new JLabel("Files of type:");
  225.     labelPanel.add(l);
  226.  
  227.     bottomPanel.add(labelPanel);
  228.     bottomPanel.add(Box.createRigidArea(hstrut25));
  229.  
  230.     // file entry and filters
  231.     JPanel fileAndFilterPanel = new JPanel();
  232.     fileAndFilterPanel.setLayout(new BoxLayout(fileAndFilterPanel, BoxLayout.Y_AXIS));
  233.  
  234.     filenameTextField = new JTextField();
  235.     filenameTextField.addActionListener(getApproveSelectionAction());
  236.     File f = getFileChooser().getSelectedFile();
  237.     if(f != null) {
  238.         setFileName(getFileChooser().getName(f));
  239.     }
  240.  
  241.     fileAndFilterPanel.add(filenameTextField);
  242.     
  243.     fileAndFilterPanel.add(Box.createRigidArea(vstrut10));
  244.  
  245.     filterComboBoxModel = createFilterComboBoxModel();
  246.     getFileChooser().addPropertyChangeListener(filterComboBoxModel);
  247.     filterComboBox = new JComboBox(filterComboBoxModel);
  248.     filterComboBox.setRenderer(createFilterComboBoxRenderer());
  249.     fileAndFilterPanel.add(filterComboBox);
  250.  
  251.     bottomPanel.add(fileAndFilterPanel);
  252.     bottomPanel.add(Box.createRigidArea(hstrut10));
  253.  
  254.     // buttons
  255.     JPanel buttonPanel = new JPanel();
  256.     buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
  257.     
  258.     approveButton = new JButton(getApproveButtonText()) {
  259.         public Dimension getMaximumSize() {
  260.         return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
  261.         }
  262.     };
  263.     approveButton.addActionListener(getApproveSelectionAction());
  264.     approveButton.setToolTipText(getApproveButtonToolTipText());
  265.     buttonPanel.add(approveButton);
  266.     buttonPanel.add(Box.createRigidArea(vstrut10));
  267.  
  268.     cancelButton = new JButton(cancelButtonText) {
  269.         public Dimension getMaximumSize() {
  270.         return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
  271.         }
  272.     };
  273.     cancelButton.setToolTipText(cancelButtonToolTipText);
  274.     cancelButton.addActionListener(getCancelSelectionAction());
  275.     buttonPanel.add(cancelButton);
  276.  
  277.     bottomPanel.add(buttonPanel);
  278.     bottomPanel.add(Box.createRigidArea(hstrut10));
  279.     }
  280.  
  281.     protected JPanel createList() {
  282.     JPanel p = new JPanel(new BorderLayout());
  283.     list = new JList();
  284.     // PENDING(jeff) - get this color from BasicLookAndFeel
  285.     // list.setBackground(Color.white);
  286.     list.setCellRenderer(new FileRenderer());
  287.     list.setModel(model);
  288.     list.addListSelectionListener(createListSelectionListener());
  289.     list.addMouseListener(createDoubleClickListener(list));
  290.     JScrollPane scrollpane = new JScrollPane(list);
  291.     scrollpane.setBorder(BorderFactory.createLoweredBevelBorder());
  292.     p.add(scrollpane, BorderLayout.CENTER);
  293.     return p;
  294.     }
  295.  
  296.     protected class FileRenderer extends BasicListCellRenderer  {
  297.  
  298.     public Component getListCellRendererComponent(JList list, Object value,
  299.                               int index, boolean isSelected, 
  300.                               boolean cellHasFocus) {
  301.  
  302.         super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  303.         File file = (File) value; 
  304.         String fileName = getFileChooser().getName(file);
  305.         setText(fileName);
  306.  
  307.         Icon icon = getFileChooser().getIcon(file);
  308.         setIcon(icon);
  309.  
  310.         return this;
  311.     }
  312.     }
  313.  
  314.  
  315.     public void uninstallUI(JComponent c) {
  316.     // Remove listeners
  317.     getFileChooser().removePropertyChangeListener(filterComboBoxModel);
  318.     cancelButton.removeActionListener(getCancelSelectionAction());
  319.     approveButton.removeActionListener(getApproveSelectionAction());
  320.     filenameTextField.removeActionListener(getApproveSelectionAction());
  321.  
  322.     super.uninstallUI(c);
  323.     }
  324.  
  325.     public Dimension getPreferredSize(JComponent x) {
  326.     return PREF_SIZE;
  327.     }
  328.     
  329.     public Dimension getMinimumSize(JComponent x) {
  330.     return MIN_SIZE;
  331.     }
  332.     
  333.     public Dimension getMaximumSize(JComponent x) {
  334.     return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
  335.     }
  336.     
  337.     /*
  338.      * Listen for filechooser property changes, such as
  339.      * the selected file changing, or the type of the dialog changing.
  340.      */
  341.     public void propertyChange(PropertyChangeEvent e) {
  342.     String prop = e.getPropertyName();
  343.     if(prop.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {
  344.         File f = (File) e.getNewValue();
  345.         if(f != null) {
  346.         setFileName(getFileChooser().getName(f));
  347.         if(model.contains(f)) {
  348.             list.setSelectedIndex(model.indexOf(e.getNewValue()));
  349.             list.ensureIndexIsVisible(list.getSelectedIndex());
  350.         }
  351.         }
  352.     } else if(prop.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) {
  353.         fileView.clearIconCache();
  354.         list.clearSelection();
  355.         File currentDirectory = getFileChooser().getCurrentDirectory();
  356.         if(currentDirectory != null) {
  357.         directoryComboBoxModel.addItem(currentDirectory);
  358.         // Enable the newFolder action if the current directory
  359.         // is writable.
  360.         // PENDING(jeff) - broken - fix
  361.         getNewFolderAction().setEnabled(currentDirectory.canWrite());
  362.         }
  363.     } else if(prop.equals(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY)) {
  364.         fileView.clearIconCache();
  365.         list.clearSelection();
  366.     } else if(prop == JFileChooser.ACCESSORY_CHANGED_PROPERTY) {
  367.         if(accessoryPanel != null) {
  368.         if(e.getOldValue() != null) {
  369.             getAccessoryPanel().remove((JComponent) e.getOldValue());
  370.         }
  371.         JComponent accessory = (JComponent) e.getNewValue();
  372.         if(accessory != null) {
  373.             getAccessoryPanel().add(accessory, BorderLayout.CENTER);
  374.         }
  375.         }
  376.     } else if(prop == JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY ||
  377.        prop == JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY) {
  378.         approveButton.setText(getApproveButtonText());
  379.         approveButton.setToolTipText(getApproveButtonToolTipText());
  380.     }
  381.     }
  382.  
  383.     public void ensureFileIsVisible(File f) {
  384.     if(model.contains(f)) {
  385.         list.setSelectedIndex(model.indexOf(f));
  386.         list.ensureIndexIsVisible(list.getSelectedIndex());
  387.     }
  388.     }
  389.  
  390.     public void rescanCurrentDirectory() {
  391.     model.invalidateFileCache();
  392.     model.validateFileCache();
  393.     }
  394.  
  395.     public String getFileName() {
  396.     if(filenameTextField != null) {
  397.         return filenameTextField.getText();
  398.     } else {
  399.         return null;
  400.     }
  401.     }
  402.  
  403.     public void setFileName(String filename) {
  404.     if(filenameTextField != null) {
  405.         filenameTextField.setText(filename);
  406.     }
  407.     }
  408.  
  409.     public String getDirectoryName() {
  410.     // PENDING(jeff) - get the name from the directory combobox
  411.     return null;
  412.     }
  413.  
  414.     public void setDirectoryName(String dirname) {
  415.     // PENDING(jeff) - set the name in the directory combobox
  416.     }
  417.  
  418.     protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer() {
  419.     return new DirectoryComboBoxRenderer();
  420.     }
  421.  
  422.     //
  423.     // Renderer for DirectoryComboBox
  424.     //
  425.     class DirectoryComboBoxRenderer extends BasicListCellRenderer  {
  426.     public Component getListCellRendererComponent(JList list, Object value,
  427.                               int index, boolean isSelected, 
  428.                               boolean cellHasFocus) {
  429.  
  430.         super.getListCellRendererComponent(list, value, index,
  431.                            isSelected, cellHasFocus);
  432.         File directory = (File) value; 
  433.         if(directory == null) {
  434.         setText("");
  435.         return this;
  436.         }
  437.         String fileName = getFileChooser().getName(directory);
  438.         setText(fileName);
  439.  
  440.         // REMIND(jeff) - pay attention to parent heirarchy and
  441.         // indent accordingly
  442.         Icon icon = getFileChooser().getIcon(directory);
  443.         setIcon(icon);
  444.  
  445.         return this;
  446.     }
  447.     }
  448.  
  449.     //
  450.     // DataModel for DirectoryComboxbox
  451.     //
  452.     protected DirectoryComboBoxModel createDirectoryComboBoxModel() {
  453.     return new DirectoryComboBoxModel();
  454.     }
  455.  
  456.     /**
  457.      * Data model for a type-face selection combo-box. 
  458.      */
  459.     protected class DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel {
  460.     Vector directories = new Vector();
  461.     File selectedDirectory;
  462.  
  463.     public DirectoryComboBoxModel() {
  464.         super();
  465.  
  466.         File[] roots = getFileChooser().getFileSystemView().getRoots();
  467.         for(int i = 0; i < roots.length; i++) {
  468.         addItem(roots[i]);
  469.         }
  470.         addItem(getFileChooser().getCurrentDirectory());
  471.     }
  472.  
  473.     public void addItem(File directory) {
  474.         if(directory != null) {
  475.         if(!directories.contains(directory)) {
  476.             directories.addElement(directory);
  477.         }
  478.         setSelectedItem(directory);
  479.         }
  480.     }
  481.  
  482.     public void setSelectedItem(Object selectedDirectory) {
  483.         this.selectedDirectory = (File) selectedDirectory;
  484.             fireContentsChanged(this, -1, -1);
  485.     }
  486.  
  487.     public Object getSelectedItem() {
  488.         return selectedDirectory;
  489.     }
  490.     
  491.     public int getSize() {
  492.         return directories.size();
  493.     }
  494.  
  495.     public Object getElementAt(int index) {
  496.         return directories.elementAt(index);
  497.     }
  498.     }
  499.  
  500.     //
  501.     // Renderer for Types ComboBox
  502.     //
  503.     protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
  504.     return new FilterComboBoxRenderer();
  505.     }
  506.  
  507.     /**
  508.      * Render different type sizes and styles.
  509.      */
  510.     public class FilterComboBoxRenderer extends BasicListCellRenderer {
  511.     public Component getListCellRendererComponent(JList list,
  512.         Object value, int index, boolean isSelected, 
  513.         boolean cellHasFocus) {
  514.  
  515.         super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  516.  
  517.         FileFilter filter = (FileFilter) value;
  518.         if(filter != null) {
  519.         setText(filter.getDescription());
  520.         } 
  521.         
  522.         return this;
  523.     }
  524.     }
  525.  
  526.     //
  527.     // DataModel for Types Comboxbox
  528.     //
  529.     protected FilterComboBoxModel createFilterComboBoxModel() {
  530.     return new FilterComboBoxModel();
  531.     }
  532.     
  533.     /**
  534.      * Data model for a type-face selection combo-box. 
  535.      */
  536.     protected class FilterComboBoxModel extends AbstractListModel implements ComboBoxModel, PropertyChangeListener {
  537.     protected FileFilter[] filters;
  538.     protected FilterComboBoxModel() {
  539.         super();
  540.         filters = getFileChooser().getChoosableFileFilters();
  541.     }
  542.     
  543.     public void propertyChange(PropertyChangeEvent e) {
  544.         String prop = e.getPropertyName();
  545.         if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) {
  546.         filters = (FileFilter[]) e.getNewValue();
  547.         fireContentsChanged(this, -1, -1);
  548.         }
  549.     }
  550.  
  551.     public void setSelectedItem(Object filter) {
  552.         if(filter != null) {
  553.         getFileChooser().setFileFilter((FileFilter) filter);
  554.         fireContentsChanged(this, -1, -1);
  555.         }
  556.     }
  557.  
  558.     public Object getSelectedItem() {
  559.         // Ensure that the current filter is in the list.
  560.         // NOTE: we shouldnt' have to do this, since JFileChooser adds
  561.         // the filter to the choosable filters list when the filter
  562.         // is set. Lets be paranoid just in case someone overrides
  563.         // setFileFilter in JFileChooser.
  564.         FileFilter currentFilter = getFileChooser().getFileFilter();
  565.         boolean found = false;
  566.         if(currentFilter != null) {
  567.         for(int i=0; i < filters.length; i++) {
  568.             if(filters[i] == currentFilter) {
  569.             found = true;
  570.             }
  571.         }
  572.         if(found == false) {
  573.             getFileChooser().addChoosableFileFilter(currentFilter);
  574.         }
  575.         }
  576.         return getFileChooser().getFileFilter();
  577.     }
  578.     
  579.     public int getSize() {
  580.         if(filters != null) {
  581.         return filters.length;
  582.         } else {
  583.         return 0;
  584.         }
  585.     }
  586.  
  587.     public Object getElementAt(int index) {
  588.         if(index > getSize() - 1) {
  589.         // This shouldn't happen. Try to recover gracefully.
  590.         return getFileChooser().getFileFilter();
  591.         }
  592.         if(filters != null) {
  593.         return filters[index];
  594.         } else {
  595.         return null;
  596.         }
  597.     }
  598.     }
  599.                     
  600.     public void valueChanged(ListSelectionEvent e) {
  601.     File f = getFileChooser().getSelectedFile();
  602.     if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) {
  603.         setFileName(getFileChooser().getName(f));
  604.     }
  605.     }
  606.  
  607.     /**
  608.      * Acts when DirectoryComboBox has changed the selected item.
  609.      */
  610.     protected class DirectoryComboBoxAction extends AbstractAction {
  611.     protected DirectoryComboBoxAction() {
  612.         super("DirectoryComboBoxAction");
  613.     }
  614.     
  615.     public void actionPerformed(ActionEvent e) {
  616.         getFileChooser().setCurrentDirectory((File) directoryComboBox.getSelectedItem());
  617.     }
  618.     }
  619.     
  620. }
  621.  
  622.